home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / raytrace / radiance / nextrad.lha / NeXtRad / CONVERT / convert.c next >
Encoding:
C/C++ Source or Header  |  1993-02-22  |  2.2 KB  |  93 lines

  1. /* convert.c */
  2.  
  3. /* this program converts an off geometry file (.geom) to an .obj file 
  4.    (used by radiosity package) */
  5. /* written by : Jason R. Wilson */
  6. /* last modified : 2/21/93 */
  7.  
  8. #include <stdio.h>
  9.  
  10. main ()
  11.  
  12. {
  13.  
  14. int NumVerts;
  15. int NumPolys;
  16. FILE *inputfp;
  17. FILE *outputfp;
  18. int loop,loop2;
  19. float x,y,z;
  20. int numvertsneeded;
  21. int a,b,c,d;
  22. char infilename[256];
  23. char outfilename[256];
  24. char answer[256];
  25. double Er,Eg,Eb,Rr,Rg,Rb;
  26. int clockwise;
  27.  
  28. /* get input from user */
  29. printf ("Please enter the name of the input file (.geom)\n");
  30. scanf ("%s",infilename);
  31. printf ("Please enter the name of the output file (.obj)\n");
  32. scanf ("%s",outfilename);
  33.  
  34. inputfp = fopen (infilename,"r"); /* open input data file */
  35. outputfp = fopen (outfilename,"w"); /* open output data file */
  36.  
  37. printf ("Is the data in the input file stored clockwise? (y or n)\n");
  38. scanf ("%s",answer);
  39.  
  40. if ((answer[0] == 'y') || (answer[0] == 'Y'))
  41.   clockwise = 1;
  42. else
  43.   clockwise = 0;
  44.  
  45. printf ("Please enter the emission values for the output file\n");
  46. scanf ("%lf %lf %lf",&Er,&Eg,&Eb);
  47. printf ("Please enter the reflectivity values for the output file\n");
  48. scanf ("%lf %lf %lf",&Rr,&Rg,&Rb);
  49. printf ("Thank you--converting ...\n");
  50.  
  51. /* convert file */
  52. fscanf (inputfp,"%d %d %d",&NumVerts,&NumPolys,&loop);
  53. fprintf (outputfp,"%d\n",NumVerts);
  54. fprintf (outputfp,"%d\n",NumPolys);
  55. fprintf (outputfp,"\n");
  56.  
  57. for (loop = 0;loop < NumVerts;loop++)
  58. {
  59.    fscanf (inputfp,"%f %f %f",&x,&y,&z);
  60.    fprintf (outputfp,"%f %f %f\n",x,y,z); 
  61. }
  62.  
  63. fprintf (outputfp,"\n");
  64.  
  65. for (loop = 0;loop < NumPolys;loop++)
  66. {
  67.    fscanf (inputfp,"%d",&numvertsneeded);
  68.    if (numvertsneeded == 3)
  69.    {
  70.       fscanf (inputfp,"%d %d %d",&a,&b,&c);
  71.       if (clockwise == 1)
  72.      fprintf (outputfp,"3 %d %d %d\n",c,b,a);
  73.       else
  74.      fprintf (outputfp,"3 %d %d %d\n",a,b,c);
  75.       fprintf (outputfp,"0 %lf %lf %lf %lf %lf %lf\n\n",Er,Eg,Eb,Rr,Rg,Rb);
  76.    }
  77.    else
  78.    {
  79.       fscanf (inputfp,"%d %d %d %d",&a,&b,&c,&d);
  80.       if (clockwise == 1)
  81.      fprintf (outputfp,"4 %d %d %d %d\n",d,c,b,a);
  82.       else
  83.      fprintf (outputfp,"4 %d %d %d %d\n",a,b,c,d);
  84.       fprintf (outputfp,"0 %lf %lf %lf %lf %lf %lf\n\n",Er,Eg,Eb,Rr,Rg,Rb);
  85.    }
  86.    
  87. }
  88. close (inputfp);
  89. close (outputfp);
  90. }
  91.    
  92.  
  93.